package com.teen9g.infoplatformserver.consumer;

import com.teen9g.infoplatformserver.MQMessage.FileUploadMessage;
import com.teen9g.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class FileUploadConsumer {

    @Autowired
    private AliOssUtil aliOssUtil;

    @RabbitListener(queues = "file.upload.queue")
    public void receiveFileUpload(FileUploadMessage message) {
        try {
            log.info("开始处理文件上传: {}", message.getFileName());
            String path = aliOssUtil.upload(message.getFileContent(), message.getFileName());
            log.info("文件上传完成: {}", path);

            // 这里可以添加通知逻辑，如发送邮件或站内通知用户上传完成
        } catch (Exception e) {
            log.error("文件处理失败: {}", e.getMessage());
            // 可以添加重试逻辑或错误处理
        }
    }
}
